<template>
  <a-modal
    :centered="true"
    :confirmLoading="confirmLoading"
    :title="title"
    :bodyStyle="{height: modalHeight()}"
    :visible="visible"
    :width="modalWidth()"
    @cancel="handleCancel"
    @ok="handleCancel"
  >
    <template slot="footer">
      <a-button key="submit" type="primary" @click="handleCancel">
        确定
      </a-button>
    </template>
    <div :style="modalStyle()">
      <a-spin :spinning="confirmLoading">
        <p v-html="content"></p>
      </a-spin>
    </div>
  </a-modal>
</template>

<script>
import { register } from '@/utils/drag_modal'
import { logMonitoringDetail } from '@/api/modular/main/knowl/log_monitoring/logMonitoringManager'

export default {
  data() {
    return {
      content: undefined,
      visible: false,
      title: '',
      confirmLoading: false
    }
  },
  methods: {
    modalWidth() {
      return document.body.clientWidth * 0.5
    },
    modalHeight() {
      return (document.body.clientHeight * 0.8) + 'px'
    },
    modalStyle() {
      return {
        'overflow-y': 'overlay',
        'overflow-x': 'hidden',
        'max-height': '100%',
        'padding-right': '9px'
      }
    },
    show(params, title, type) {
      console.log(params)
      this.title = title
      this.visible = true
      register(true)
      switch (type) {
        case 0:
          this.content = params['triggerMsg']
          break
        case 1:
          this.content = params['handleMsg']
          break
        case 2:
          this.loadDetail(params)
          break
        default:
          break
      }
    },
    loadDetail(params) {
      this.confirmLoading = true
      const time = this.$moment(params['triggerTime']).valueOf()
      logMonitoringDetail({
        'executorAddress': params['executorAddress'],
        'logId': params['id'],
        'triggerTime': time,
        'fromLineNum': 1
      })
        .then((res) => {
          if (res.code === 200) {
            this.content = res.content.logContent
          }
        }).catch((e) => {
        console.log(e)
      }).finally(() => {
        this.confirmLoading = false
      })
    },
    handleCancel() {
      register(false)
      this.content = undefined
      this.visible = false
    }
  }
}
</script>

<style lang="less" scoped>
::-webkit-scrollbar {
  width: 2px;
  background-color: rgba(240, 240, 240, 1);
}
</style>
